//初始化模型，自动生成
var DataTypes = require('sequelize').DataTypes
var _edu_categories = require('./edu_categories')
var _edu_chapters = require('./edu_chapters')
var _edu_courses = require('./edu_courses')
var _edu_test = require('./edu_test')
var _edu_tests = require('./edu_tests')
var _edu_users = require('./edu_users')
var _edu_videos = require('./edu_videos')

function initModels(sequelize) {
  var edu_categories = _edu_categories(sequelize, DataTypes)
  var edu_chapters = _edu_chapters(sequelize, DataTypes)
  var edu_courses = _edu_courses(sequelize, DataTypes)
  var edu_test = _edu_test(sequelize, DataTypes)
  var edu_tests = _edu_tests(sequelize, DataTypes)
  var edu_users = _edu_users(sequelize, DataTypes)
  var edu_videos = _edu_videos(sequelize, DataTypes)

  //以下为关联关系
  edu_courses.belongsTo(edu_categories, { as: 'cat', foreignKey: 'cat_id' })
  edu_categories.hasMany(edu_courses, {
    as: 'edu_courses',
    foreignKey: 'cat_id'
  })
  edu_videos.belongsTo(edu_chapters, {
    as: 'chapter',
    foreignKey: 'chapter_id'
  })
  edu_chapters.hasMany(edu_videos, {
    as: 'lessonInfo',
    foreignKey: 'chapter_id'
  })
  edu_chapters.belongsTo(edu_courses, { as: 'course', foreignKey: 'course_id' })
  edu_courses.hasMany(edu_chapters, {
    as: 'edu_chapters',
    foreignKey: 'course_id'
  })

  return {
    edu_categories,
    edu_chapters,
    edu_courses,
    edu_test,
    edu_tests,
    edu_users,
    edu_videos
  }
}
module.exports = initModels
module.exports.initModels = initModels
module.exports.default = initModels
